<?php
/*=============================================================================
|| ##################################################################
||	phpFoX Konsort
|| ##################################################################
||
||	Copyright		: (C) 2005-2007 PHPFOX Limited a Reality Fox Creation
||	Contact			: info@phpfox.com
||
||	- phpFoX and all of its source code and files are protected by Copyright Laws.
||
||	- The license for phpFoX permits you to install this software on a single domain (.com, .org, .net, etc.).
||
||	- You may also not remove this copyright screen which shows the copyright information and credits for phpFoX (RealityFOX Creations).
||
||	- phpFoX Konsort is NOT a FREE software - http://www.phpfox.com/license/
||
|| ##################################################################
=============================================================================*/

/* $File: ./include/modules/Listing/classes/PhpFox_ComponentListingView.class.php, $Author:  $ */



/** Display list classifieds
 *
 * Parameters:
 *  1. oUser (mandatory) - user account object
 *
 * @package module.listing
 * @version $Id:
 *   PHPFox Team ()
 */
class PhpFox_Mod_Listing_ComponentListingView extends BaseComponent
{
	function process()
	{
	    //check permissions
        $oSecurityService = App::getModuleService('Account', 'Security');
		/* @var $oSecurityService PhpFox_Mod_Account_ServiceSecurity */
		$oListingService = $this->_oModule->getService('Listing');
		$oSecurityService->checkPerm('listing', array('read_only', 'full'));
        /* @var $oGroupsService PhpFox_Mod_Groups_ServiceGroups */
        $bRead = ($oSecurityService->checkPerm('listing', array('read_only'), false)) ? true : false;
        $oReq = &App::getRequest();

        if(!$oReq->getInt('id'))
            App::gotoUrl('public.listing');
        /* @var $oReq Request */
        $aCatHash = $oListingService->getCategoryHash();
        $aListing = $oListingService->getListingById($oReq->getInt('id'));
        if(empty($aListing))
            App::gotoUrl('public.listing');
        $bOwner = ($oSecurityService->getCurrentUserLogin() == $aListing['user']) ? true : false;
        $bAdmin = ($oSecurityService->isAdmin()) ? true : false;
        $bStaff = $oSecurityService->isStaff();
        //action block
        if($oReq->getInt('rep'))
        {
        	$oTxt = &App::newObject('Text');
            if($bRead)
            {
                App::gotoUrl('public.denied');
			}
            $_SESSION['compose']['subject'] = ''. App::format('Mod_Listing.classified') .': '. $oTxt->preParseText($aListing['title']);
            $_SESSION['compose']['user'] = $aListing['user'];
            $sMessage = '--------- '. App::format('Mod_Listing.classified_posting') .' --------------------------------------
[listing]'.$aListing['id'].'[/listing]
[quote="'.$aListing['user'].'"]
'. $oTxt->preParseText($aListing['text']) .'
[/quote]';
            $_SESSION['compose']['message'] = $oTxt->preParseText($sMessage);
            App::gotoUrl('public.account.messages.compose');

        }
        if($oReq->getInt('fwd'))
        {
            if($bRead)
            {
                App::gotoUrl('public.denied');
			}

			$oTxt = &App::newObject('Text');

            $_SESSION['compose']['subject'] = ''. App::format('Mod_Listing.classified') .': '. $oTxt->preParseText($aListing['title']);
            $sMessage = '--------- '. App::format('Mod_Listing.classified_posting') .' --------------------------------------
[listing]'.$aListing['id'].'[/listing]
[quote="'.$aListing['user'].'"]
'. $oTxt->preParseText($aListing['text']) .'
[/quote]';
            $_SESSION['compose']['message'] = $oTxt->preParseText($sMessage);
            App::gotoUrl('public.account.messages.compose');
        }
        if($oReq->getInt('del'))
        {
            $oSecurityService->checkPerm('listing', array('full'));
            if(!($bOwner || $bAdmin || $bStaff))
                App::gotoUrl('public.listing');
            else
            {
                $oListingService->deleteItem($oReq->getInt('id'));
                App::gotoUrl('public.listing', array(), array(App::format('Mod_Listing.item.deleted')), false, 'View');
            }
        }
        if($oReq->getInt('edit'))
        {
            if(!$bOwner)
                App::gotoUrl('public.listing');
            else
                App::gotoUrl('public.listing.create', array('id'=>$aListing['id']));
        }

        $oListingService->updateView($oReq->getInt('id'));
        $oTpl = $this->_oModule->getTemplate();

        $oTpl->assign(array(
                             'aCatHash' => $aCatHash,
        ));
        $oTpl->assignSrc(array(
                               'aList' => $aListing,
                               'aErrors'  => $this->getErrors(),
                               'sCurrentUser' => $oSecurityService->getCurrentUserLogin(),
                               'sImageUrl'=> App::getParam('user.pic.url'),
                               'bOwner' => $bOwner,
                               'bAdmin' => !$bAdmin && !$bStaff ? false : true,
                                ));

        $srcHtml = $oTpl->fetch('ListingView.html');
		return $srcHtml;
	}
}
?>